{{template "base/base.html" .}}
{{define "head"}}
<title>sss</title>
{{end}}
{{define "body"}}
<div class="testing">
<header class="main">
	<h1><strong>Retina</strong> Dashboard</h1>
	<!--<input type="text" value="search" />-->
</header>
<section class="user">
	<div class="profile-img">
		<p><img src="images/uiface2.png" alt="" height="40" width="40" /> Welcome back John Doe</p>
	</div>
	<div class="buttons">
        <span class="button blue"><a href="/admin/login_out/{{.tel}}">登出</a></span>
	</div>
</section>
</div>
<nav>
	<ul>
        <li><a href="/admin/index/{{.tel}}"><span class="icon">&#128711;</span> 设备监控</a></li>
        <li class="section"><a href="/admin/admin_list/{{.tel}}"><span class="icon">&#128101;</span>管理员<span class="pip">3</span></a></li>
        <li>
            <a href="/admin/sys_setting/{{.tel}}"><span class="icon">&#9881;</span>系统设置</a>
        </li>
        <li>
            <a href="/admin/show_remote_list/{{.tel}}"><span class="icon">&#9881;</span>显示遥控数据</a>
        </li>
        <li>
            <a href="/admin/add_remote_data/{{.tel}}"><span class="icon">&#9881;</span>添加遥控数据</a>
        </li>
	</ul>
</nav>

<section class="alert">
        <button href="#updateData" rel="leanModal" class="green">更改信息</button>
		 <button href="#OpenWindow" rel="leanModal" class="green">添加新的管理员</button>
        <button id="del_btn" class="green">删除</button>
</section>
<section class="content">
	<section class="widget">
		<header>
			<span class="icon">&#128100;</span>
			<hgroup>
				<h1>Users</h1>
				<h2>Current member accounts</h2>
			</hgroup>
			<aside>
				<span>
					<a href="#">&#9881;</a>
					<ul class="settings-dd">
						<li><label>Option a</label><input type="checkbox" /></li>
						<li><label>Option b</label><input type="checkbox" checked="checked" /></li>
						<li><label>Option c</label><input type="checkbox" /></li>
					</ul>
				</span>
			</aside>
		</header>
		<div class="content">
			<table id="myTable" border="0" width="100">
				<thead>
					<tr>
                        <th>选中</th>
						<th class="avatar">Name</th>
						<th>Tel</th>
						<th>Password</th>
						<th>Date</th>
					</tr>
				</thead>
					<tbody id="user_list">

					</tbody>
				</table>
		</div>
	</section>
</section>
	
    <div id="OpenWindow" class="register">
    <section>
        <div id="signup-ct">
            <div id="OpenWindow-header">
                <h1 id="login_title">
                    <strong>添加新的管理员</strong>
                </h1>
                <p>
                <a href="#" class="modal_close"></a>
            </div>
           <!-- <form id="register_form" >-->
            <div class="txt-fld">
                <label for="">
                    电话号码</label>
                <input type="text" name="Tel"  id="Tel" />
            </div>
            <div class="txt-fld">
                <label for="">
                    姓名</label>
                <input type="text" name="UserName" id="UserName" />
            </div>
            <div class="txt-fld">
                <label for="">
                    密码</label>
                <input type="text" name="UserPw" id="UserPw" />
            </div>
             <!--<div class="txt-fld">-->
                <!--<label for="">-->
                    <!--再次输入密码</label>-->
                <!--<input type="text" name="ReUserPw" id="ReUserPw" />-->
            <!--</div>-->
            <div class="btn-fld">
                <button id="subButton" class="blue" type="submit">注册 »</button>
            </div>
             <!--</form>-->
        </div>
        </section>
    </div>
<div id="updateData" class="updateData">
    <section>
        <div id="signup-ct">
            <div id="OpenWindow-header">
                <h1 id="login_title">
                    <strong>更改信息</strong>
                </h1>
                <p>
                    <a href="#" class="modal_close"></a>
            </div>
            <!-- <form id="register_form" >-->
            <div class="txt-fld">
                <label for="">
                    电话号码</label>
                <input type="text" value="{{.admin.Tel}}" name="Tel"  id="updateTel" />
            </div>
            <div class="txt-fld">
                <label for="">
                    姓名</label>
                <input type="text" name="updateUserName" value="{{.admin.UserName}}" id="updateUserName" />
            </div>
            <div class="txt-fld">
                <label for="">
                    密码</label>
                <input type="text" name="updateUserPw" value="" id="updateUserPw" />
            </div>
            <div class="btn-fld">
                <button id="UpdateButton" class="blue" type="submit">更新</button>
            </div>
            <!--</form>-->
        </div>
    </section>
</div>
<script type="text/javascript">
$(function () {
    var tel = {{.tel}}
    $(document).ready(function() {
     $.getJSON('http://'+window.location.host+'/admin/api/get_admin_list/'+tel, function(data) {
			console.log(data)
        	$.each(data,function(index,element){
				    $("#user_list").append('<tr><td><input type="checkbox" name="checkbox" id="{{.tel}}"></td>'+'<td class="avatar">'+ element.UserName+'</td><td>'+element.Tel+'</td><td>'+element.UserPw+'</td><td>'+element.Createtime+'</td></tr>')

			});
    	});

    });
 /*   $(":button[class='del_btn']").click(function(){
		        alert("ddd")
		});
		*/

});
</script>

<script type="text/javascript">
    $(document).ready(function() {

        $("#del_btn").click(function(){
        var objs = $(":input[type='checkbox'][name='checkbox']")
        var tels = {"Tel":[]};
            var num = objs.length

            for(var i=0;i< num;i++){
                    if(objs[i].checked == true){
                        //console.log(objs[i].id)
                        tels.Tel.push(objs[i].id)
                 }
             }
            if (tels.length <= 0){
                alert("选中一个你要删除的用户");
                return false
            }
 /*           $.post('http://'+window.location.host+'/admin/api/del_admins/'+{{.tel}},data,function(data){
				            console.log(data)
		                    if(data.RespCode == 200){
					             alert(data.Msg);
				            }else if(data.RespCode == 8){
					             alert(data.Msg);
				            }

		            });*/
		            $.ajax({
                        url:'http://'+window.location.host+'/admin/api/del_admins/'+{{.tel}},
                        type:"POST",
                        dataType:"json",
                        data:JSON.stringify(tels),
                        success: function(data){
                               if(data.RespCode == 205){
                                    alert("有帐号删除失败");
                                    window.location.reload()
                               }else if((data.RespCode == 200)){
                                    window.location.reload()
                               }
                        }
		            });


        });
});
</script>
<script type="text/javascript">
$(function () {
        $("#UpdateButton").click(function(){
			//alert(window.location.host);
           if(!$("#updateTel").val().match(/^(((13[0-9]{1})|159|153)+\d{8})$/)){
                alert("输入的手机号有误");
                return false;
            }
	        var UserName = $("#updateUserName").val();
			var Tel = $("#updateTel").val();
			var UserPw = $("#updateUserPw").val();
			var data = {'Tel':Tel,'UserName':UserName,'UserPw':UserPw}
            //console.log(data)
			$.post('http://'+window.location.host+'/admin/api/update_admin/'+{{.tel}},data,function(data){
				console.log(data)
				if(data.RespCode == 200){
					alert(data.Msg);
					window.location.reload()
				}else if(data.RespCode == 202){
					alert(data.Msg);
				}

			});
			return false;
		});
});
</script>
<script type="text/javascript">
 $(document).ready(function()
        {
			
        $("#subButton").click(function(){
			//alert(window.location.host);
			
	        var UserName = $("#UserName").val();
			 var Tel = $("#Tel").val();
			var UserPw = $("#UserPw").val();
			var data = {'Tel':Tel,'UserName':UserName,'UserPw':UserPw}
			$.post('http://'+window.location.host+'/admin/api/register/'+{{.tel}},data,function(data){
				console.log(data)
				if(data.RespCode == 200){
					alert("添加用户成功");
					 window.location.reload()
				}else{
					alert(data.Msg);
				}
				
			});
			return false;
		});
});
</script>
<script type="text/javascript">
        $(document).ready(function () {
            //$('#aOpen').leanModal({ top: 100, closeButton: ".modal_close" });
            $('button[rel*=leanModal]').leanModal({ top: 100, closeButton: ".modal_close" });
        });
    </script>
{{end}}